package com.example.question.list.list1;

/**
 * @Date 2023-07-04
 * @Author Jonathan
 * @link {<a href="https://leetcode.cn/problems/linked-list-cycle/">...</a>}
 */
public class Code08_141 {
    public static void main(String[] args) {
        Code08_141 code = new Code08_141();
    }

    /**
     * 还可以用一个set来保存
     *
     * @param head
     * @return
     */
    public boolean hasCycle(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                return true;
            }
        }
        return false;
    }
}
